//
//  PopoverPresentationController.m
//  Weibo
//
//  Created by qiang on 4/26/16.
//  Copyright © 2016 QiangTech. All rights reserved.
//

#import "PopoverPresentationController.h"

@implementation PopoverPresentationController

// 布局转场子视图时调用
- (void)containerViewDidLayoutSubviews
{
    // 1. 修改弹出视图的消息
//    self.presentedView.frame = CGRectMake(100, 50, 200, 200);
    self.presentedView.frame = self.presentFrame;
    
    // 2. 在容器视图上添加一个蒙版
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];
    bgView.frame = [UIScreen mainScreen].bounds;
    [self.containerView insertSubview:bgView atIndex:0];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDo:)];
    [bgView addGestureRecognizer:tap];
}

- (void)tapDo:(UITapGestureRecognizer *)g
{
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
